package com.sr.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.entity.Author;
import com.sr.service.AuthorService;

/**
 * Servlet implementation class UpdateInforServlet
 */
@WebServlet("/updateinf")
public class UpdateInforServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateInforServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("textml; charset=UTF-8");
		int id=Integer.parseInt(request.getParameter("id"));
		String username=request.getParameter("username");
		String penname=request.getParameter("penname");
		System.out.println(penname);
		String idcard=request.getParameter("idcard");
		System.out.println(idcard);
		Author author=new Author(id,username,idcard,penname);
		AuthorService as=new AuthorService();
		
		boolean result=as.update(author);
		System.out.println("修改"+author);
		if(result){
			request.getSession().setAttribute("a", author);
			request.getRequestDispatcher("updateinformation.jsp").forward(request, response);
			
		}else{
			request.getRequestDispatcher("information.jsp").forward(request, response);
		}
		
		
	}

}
